package com.spring.cloud.controller;

import com.alibaba.fastjson.JSON;
import com.spring.cloud.entity.User;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.*;

/**
 * Created by Administrator on 2017/3/31.
 */
@RestController
public class RobotController {

    private static Logger logger = LoggerFactory.getLogger(RobotController.class);

    @Autowired
    DiscoveryClient discoveryClient;

    @ApiOperation(value = "添加User服务", notes = "添加User对象")
    @ApiImplicitParam(name = "user", value = "用户实体", required = true, dataType = "User")
    @RequestMapping(value = "/user", method = RequestMethod.POST)
    public String user(@RequestBody User user) {
        logger.info(JSON.toJSONString(user));
        return "successfully";
    }


    @ApiOperation(value = "机器人打扫服务", notes = "根据机器人名称指令其打扫卫生")
    @ApiImplicitParam(name = "name", value = "机器人名称", required = true, dataType = "String", paramType = "query")
    @RequestMapping(value = "/sweep", method = RequestMethod.POST)
    public String sweep(@RequestParam("name") String name) {
        logger.info(JSON.toJSONString(discoveryClient));
        logger.info("robot [ " + name + " ] begin sweeping !");
        return "successfully";
    }

    @ApiOperation(value = "机器人打招呼服务", notes = "机器人看到主人打招呼")
    @RequestMapping(value = "/say", method = RequestMethod.GET)
    public String say() {
        logger.info(JSON.toJSONString(discoveryClient));
        logger.info("robot sya hello to master !");
        return "successfully";
    }

    @RequestMapping(value = "/info", method = RequestMethod.GET)
    public String info() {
        logger.info(JSON.toJSONString(discoveryClient));
        return "successfully";
    }

}
